//引入createSlice 创建reducer和action 
import {
    createSlice
} from '@reduxjs/toolkit'

const countSlice = createSlice({
    name:'counter',

    //初始数据
    initialState:{
        count:0
    },
    //这里面的会生成action，在这里书写普通action
    reducers:{
        incrementAction(prev,action){
            console.log(prev.count,action);
            prev.count += action.payload
        },

        decrementAction(prev,action){
            
            prev.count -= action.payload
        }
    }

})

//把reducer暴露出去给store用
export default countSlice.reducer


//把action暴露出去给count用
export const {
    incrementAction,
    decrementAction
} = countSlice.actions